package Aleehot100;

/**
 * ClassName: c084
 * Package: Aleehot100
 * Description:279. 完全平方数
 *
 * @Author BCXJ
 * @Create 2025/9/8 08:46
 * @Version 1.0
 * @Since 1.0
 */
public class c084 {
    public static void main(String[] args) {

    }

    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        // 最坏的情况， n = 1 + 1 + 1....
        for (int i = 1; i <= n; i++) {
            dp[i] = i;
        }

        // 遍历
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j * j <= i; j++) {
                int money = j * j;
                // 计算结果
                dp[i] = Math.min(dp[i], dp[i - money] + 1);
            }
        }
        return dp[n];
    }

}
